package com.woniuxy.seckill.mapper;

import com.hc.entity.Seckill;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

/**
 * @BelongsProject: hc
 * @BelongsPackage: com.woniuxy.seckill.mapper
 * @Author: WY
 * @CreateTime: 2022-10-25  15:18
 * @Descriprion: 秒杀表mapper
 * @Version: 1.0
 **/
public interface SeckillMapper {

    /**
     * 根据商家id查询要发布的秒杀信息
     * @param sid
     * @return
     */
    @Select("select * from hc_second_kill where id = (select max(id) from hc_second_kill where shop_id=#{sid}) and status='y'")
    @Results(
            {
                    @Result(column = "id",property = "id",id = true),
                    @Result(column = "starttime",property = "startTime"),
                    @Result(column = "num",property = "num"),
                    @Result(column = "secprice",property = "secprice"),
                    @Result(column = "endtime",property = "endTime"),
                    @Result(column = "good_id",property = "goods",one = @One(select = "com.woniuxy.seckill.mapper.GoodsMapper.findById",fetchType = FetchType.LAZY))
            }
    )
    Seckill findByShopId(Integer sid);

    /**
     * 根据id修改秒杀信息为n（已使用）
     * @param id
     */
    @Update("update hc_second_kill set status='n' where id=#{id}")
    void updatestatus(Integer id);

}
